Ext.define('navigationField', {
    extend: 'Ext.form.field.Display',
    width: '9%',
    fieldCls: 'nav',
    margin: '50 0 0 10',
    // listeners: [{
    //     render: function (p) {
    //         p.getEl().on('click', function () {
    //             alert('hhh');
    //         });
    //     }
    // }]
});
Ext.onReady(function () {
    var viewPort = Ext.create('Ext.Viewport', {
        title: 'Border Layout',
        layout: 'border',
        items: [{
            region: 'north',
            height: '10%',
            border: false,
            margin: '0,0,0,0',
            bodyStyle: 'background: #4481CE',
            layout: 'hbox', //横向格子布局
            items: [{
                xtype: 'panel',
                width: '60%',
                height: '100%',
                border: false,
                bodyStyle: 'background: #4481CE',
                items: [{
                    xtype: 'panel',
                    layout: 'hbox', //横向格子布局
                    border: false,
                    bodyStyle: 'background: #4481CE',
                    items: [
                        Ext.create('navigationField', {
                            value: '个人空间',
                            listeners: [{
                                render: function (p) {
                                    p.getEl().on('click', function () {
                                        Ext.getCmp('centerRegion').removeAll(false);
                                        Ext.getCmp('westRegion').removeAll(false);
                                        Ext.getCmp('westRegion').setHidden(true);
                                        Ext.getCmp('centerRegion').add(personSpaceTabPanel);
                                        personSpaceTabPanel.down('#viewPort').removeAll(false);
                                        personSpaceTabPanel.down('#viewPort').add(personalViewPort);//因为老师他们不需要这个viewPort
                                        personSpaceTabClick(0);
                                        personSpaceTabPanel.setActiveTab(0);
                                    });
                                }
                            }]
                        }),
                        Ext.create('navigationField', {
                            value: '测试审核',
                            listeners: [{
                                render: function (p) {
                                    p.getEl().on('click', function () {
                                        Ext.getCmp('centerRegion').removeAll(false);
                                        Ext.getCmp('westRegion').removeAll(false);
                                        Ext.getCmp('westRegion').setHidden(true);
                                        Ext.getCmp('centerRegion').add(testCheckGrid);
                                    });
                                }
                            }]
                        }),
                        Ext.create('navigationField', {
                            value: '测试需求',
                            listeners: [{
                                render: function (p) {
                                    p.getEl().on('click', function () {
                                        Ext.getCmp('centerRegion').removeAll(false);
                                        Ext.getCmp('westRegion').removeAll(false);
                                        Ext.getCmp('westRegion').setHidden(false);
                                        testRequirementStore.load();
                                        Ext.getCmp('westRegion').add(testRequirementLeftTree);
                                    });
                                }
                            }]
                        }),
                        Ext.create('navigationField', {
                            value: '测试设计',
                            listeners: [{
                                render: function (p) {
                                    p.getEl().on('click', function () {
                                        Ext.getCmp('centerRegion').removeAll(false);
                                        Ext.getCmp('westRegion').removeAll(false);
                                        Ext.getCmp('westRegion').setHidden(false);
                                        testDesignStore.reload();
                                        Ext.getCmp('westRegion').add(testDesignLeftTree);
                                    });
                                }
                            }]
                        }),
                        Ext.create('navigationField', {
                            value: '测试执行',
                            listeners: [{
                                render: function (p) {
                                    p.getEl().on('click', function () {
                                        Ext.getCmp('centerRegion').removeAll(false);
                                        Ext.getCmp('westRegion').removeAll(false);
                                        Ext.getCmp('westRegion').setHidden(false);
                                        testRunStore.reload();
                                        Ext.getCmp('westRegion').add(testRunLeftTree);
                                    });
                                }
                            }]
                        }),
                        Ext.create('navigationField', {
                            value: '测试分析',
                            listeners: [{
                                render: function (p) {
                                    p.getEl().on('click', function () {
                                        Ext.getCmp('centerRegion').removeAll(false);
                                        Ext.getCmp('westRegion').removeAll(false);
                                        Ext.getCmp('westRegion').setHidden(true);
                                        analysisGridStore.proxy.url = zuulUrl + '/' + testServiceName + '/testProject/analysis/' + currentProjectId + '/root';
                                        analysisGridStore.reload();
                                        Ext.getCmp('centerRegion').add(trqAnalysisGrid);
                                    });
                                }
                            }]
                        }),
                        Ext.create('navigationField', {
                            value: 'BUG提交',
                            listeners: [{
                                render: function (p) {
                                    p.getEl().on('click', function () {
                                        Ext.getCmp('centerRegion').removeAll(false);
                                        Ext.getCmp('westRegion').removeAll(false);
                                        Ext.getCmp('westRegion').setHidden(true);
                                        testProjectBugGridStore.proxy.url = zuulUrl + '/' + testServiceName + '/testProject/bug/list/' + currentProjectId;
                                        testProjectBugGridStore.reload();
                                        Ext.getCmp('centerRegion').add(testProjectBugGrid);
                                    });
                                }
                            }]
                        })
                        // Ext.create('navigationField', {
                        //     value: '教学白板'
                        // }),
                        // Ext.create('navigationField', {
                        //     value: '视频会议'
                        // })
                    ]
                }]
            }, {
                xtype: 'panel',
                width: '40%',
                height: '100%',
                border: false,
                bodyStyle: 'background: #4481CE',
                items: [{
                    xtype: 'toolbar',
                    style: 'background: #4481CE',
                    border: false,
                    items: ['->', {
                        xtype: 'button',
                        text: '查看测试系统信息',
                        tooltip: '查看测试系统信息',
                        icon: 'static/images/icons/fam/book.png',
                        listeners: [{
                            click: function () {
                                testSystemCleanForm(0);
                                var data = testSystemGetDetail(currentProjectId, 0);
                                testSystemPutDataIntoForm(data, 0);
                                testRequirementSystemWin.show();
                            }
                        }]
                    }, '-', {
                        xtype: 'button',
                        itemId: 'checkOnWorkButton',
                        text: '签到',
                        tooltip: '单个项目每天最多签到5次',
                        icon: 'static/images/icons/fam/accept.png',
                        listeners: [{
                            click: function () {
                                Ext.Ajax.request({
                                    url: zuulUrl + '/' + testServiceName + '/checkOnWork',
                                    method: 'post',
                                    async: false, //ASYNC 是否异步( TRUE 异步 , FALSE 同步)
                                    params: {
                                        userId: currentUserId,
                                        projectId: currentProjectId
                                    },
                                    success: function (response, opts) {
                                        var count = response.responseText;
                                        viewPort.down('#checkOnWorkButton').setDisabled(count >= 5);
                                        viewPort.down('#checkOnWorkButton').setText('签到(今日已签到' + count + '次)');
                                    },
                                    failure: function (response, opts) {
                                        var obj = Ext.decode(response.responseText);
                                        if (obj.code == 408)
                                            Ext.Msg.alert("Error", obj.message);
                                        else
                                            Ext.Msg.alert("Error", "获取签到次数失败！");
                                    }
                                });
                            }
                        }]
                    }, '-', {
                        xtype: 'splitbutton',
                        text: 'hi ~ ' + currentUser,
                        tooltip: '当前用户:' + currentUser,
                        icon: 'static/images/icons/fam/user.gif',
                        menu: new Ext.menu.Menu({
                            items: [{
                                text: '注销',
                                icon: 'static/images/icons/fam/delete.gif',
                                handler: function () {
                                    userLogout();
                                }
                            }, {
                                text: '返回上一界面',
                                icon: 'static/images/icons/fam/back.ico',
                                handler: function () {
                                    delChooseProjectCache();
                                    location.reload();//直接刷新页面就好
                                }
                            }]
                        })
                    }]
                }]
            }]
        }, taskTabPanel, {
            region: 'west',
            id: 'westRegion',
            margin: '5 5 5 5',
            title: '菜单栏',
            width: '21%',
            layout: 'fit',
            split: true,//设置能不能鼠标拖动改变宽度
            collapsible: true,    // 有没有按钮向内缩进
            //items: testRequirementLeftTree,//将你上面定义的树形组件放进去
            frame: true//边框圆润一点
        }, {
            region: 'center',
            id: 'centerRegion',
            margin: '5 5 0 0',
            border: false,
            layout: 'fit',//如果设置了这个纵向滚动条就不会出来了
            header: false,
            listeners: [{
                beforeremove: function (th, component, eOpts) {
                    if (component.id == "testRequirementEditorForm") {
                        component.setHidden(true);
                        return false;
                    } else {
                        return true;
                    }
                }
            }]
        }]
    });
    Ext.getCmp('centerRegion').add(testRequirementEditorForm);//将测试需求的表单的表单显示到中心区域
    //获取此人今天打卡了多少次
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/checkOnWork/' + currentProjectId + '/' + currentUserId,
        method: 'get',
        async: false, //ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        success: function (response, opts) {
            var count = response.responseText;
            viewPort.down('#checkOnWorkButton').setText('签到(今日已签到' + count + '次)');
            viewPort.down('#checkOnWorkButton').setDisabled(count >= 5);
        },
        failure: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (obj.code == 408)
                Ext.Msg.alert("Error", obj.message);
            else
                Ext.Msg.alert("Error", "获取签到次数失败！");
        }
    });
    chatOnlineKey = getUuid();//生成Key
    webSocket = createWebSocket('ws://' + gateWayUrl + '/websocket/chat/' + currentUserId + '/' + chatOnlineKey);//进行webSocket连接
});